home *** CD-ROM | disk | FTP | other *** search
- The following is a Pascal assignment that I had in data structures. It
- implements a stack for storing data using pointers. It is probably of
- use to you if you want to learn something about stack data structures and
- pointers. Before digging into the code perhaps you want to get a book on
- data structures and read up on what a stack is. Happy computing!!
-
- Chris Maeder
-
-
- STACK ASSIGNMENT
-
- Data Structures
- Fall 1985
-
- Write a program that uses a stack to evaluate expressions written in Polish
- postfix notation. Include separate subprograms called Push and Pop.
- Implement the stack using a linked list.
-
- The parameters for Push should be a pointer variable to hold the top of the
- stack and a real variable to hold a number. Push creates a new node and puts
- it on top of the stack.
-
- Pop needs a parameter for the top of the stack. It returns a number. It also
- disposes of the popped node. If the stack is empty, EMPTY (set to negative
- maxint) is returned. The calling routine must always check for this.
-
- The data consists of expressions input as character strings. Read characters
- in an expression until end of file is reached.
-
- Valid operators are +, -, *, /, and ^. A valid operand is any real or integer
- number with a maximum of 10 places including the decimal point if one exists.
- Blanks separate operators from operands. All arithmetic should be real. A
- negative number has a minus sign immediately preceding it.
-
- Output consists of an echo print of the input expression and either the result
- of the evaluation of the expression or an error message. Additional output,
- e.g. tracing the contents of the stack is optional but certainly useful for
- debugging.
-
- Some expressions are in error so check for:
-
- 1. An invalid character in an expression.
- 2. A malformed expression.
-
- Note:
-
- 2 5 - is interpreted as 2-5 (not 5-2)
- 6 2 / is interpreted as 6/2
- 4 2 ^ is interpreted as 4 squared